package controller;

import Reader.Profile;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import sun.rmi.runtime.Log;
import utils.HeartbeatClient;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@RestController
@Slf4j
@RequestMapping("/testcontroller")
public class testcontroller {
    @Resource
    private HeartbeatClient heartbeatClient;
    @Resource
    private Profile profile;

    @PostMapping("/test")
    @ResponseBody
    public String test(@RequestBody JSONObject object) throws InterruptedException, IOException {

            String str="";
//        String readerfilebyservletcontext = profile.readerfilebyservletcontext(object);
//        return readerfilebyservletcontext;
        try {
            String url="http://localhost:9999/updatetestchange";
            CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
            HttpPost httpPost=new HttpPost(url);

            String string = object.toString();
            HttpEntity entry =new StringEntity(string,"UTF-8");
            httpPost.setEntity(entry);
            httpPost.setHeader("Content-Type","application/json");
            CloseableHttpResponse response = closeableHttpClient.execute(httpPost);
            int statusCode = response.getStatusLine().getStatusCode();
//            log.info("================="+statusCode);
            str="修改成功";
        }catch (Exception e){

        }
        return str;

    }
}
